package com.snake.springboot.custom.service.assemble.bill;


import com.snake.springboot.custom.api.model.bill.BillPlaceOrderModel;
import com.snake.springboot.custom.api.model.pay.PayActModel;
import com.snake.springboot.custom.api.model.pay.PayActRetModel;
import com.snake.springboot.custom.api.request.bill.BilGoPayModel;
import com.snake.springboot.custom.api.request.bill.BillGoRetModel;
import com.snake.springboot.custom.api.request.bill.BillQuery;
import com.snake.springboot.custom.api.response.bill.BillRsp;
import com.snake.springboot.custom.dao.mybatis.entity.bill.BillDO;
import org.snake.common.security.account.AccountData;
import org.snake.common.security.account.LoginAccount;
import org.snake.common.utils.PropertyUtils;

/**
 * <p>账单组装器
 * 类{@code BillAssemble} </br>
 * 创建时间2025/4/6 9:49
 *
 * @author yangxt
 * @see
 */
public class BillAssemble {
    public static BillRsp toBillRsp(BillPlaceOrderModel data) {
        BillRsp rsp = new BillRsp();
        PropertyUtils.copyProperties(rsp,data);
        return rsp;
    }

    public static BillRsp toBillRsp(BillDO data) {
        BillRsp rsp = new BillRsp();
        PropertyUtils.copyProperties(rsp,data);
        return rsp;
    }

    public static BillDO toBillDO(BillPlaceOrderModel data) {
        AccountData account = LoginAccount.orNullUser();
        BillDO billDO = new BillDO();
        PropertyUtils.copyProperties( billDO,data);
        if (null != account) {
            billDO.setOperatorId(account.getAccountId());
            billDO.setOperator(account.getAccount());
        }
        return billDO;
    }

    public static BillDO toBillDO(BillQuery data) {
        BillDO billDO = new BillDO();
        PropertyUtils.copyProperties( billDO,data);
        return billDO;
    }



    public static PayActModel toPayModel(BillDO billDO, BilGoPayModel model) {
        PayActModel actModel =new PayActModel();
        actModel.setPayAmount(billDO.getPayAmount());
        actModel.setPaySource(model.getPaySource());
        actModel.setPayAccType(model.getPayAccType());
        actModel.setPayCode(billDO.getBillId());
        actModel.setModule(billDO.getBillType());
        actModel.setPayRemark(billDO.getGoodsName());
        actModel.setCallbackUrl("http://snake-custom/custom/bill/callback");
        return actModel;
    }

    public static PayActRetModel actRetModelAss(BillDO billDO, BillGoRetModel model) {
        billDO.setRetAmount(billDO.getPayAmount());
        PayActRetModel actRetModel =new PayActRetModel();
        actRetModel.setRetRemark(model.getRetRemark());
        actRetModel.setPayId(billDO.getPayId());
        actRetModel.setRetAmount(billDO.getRetAmount());
        return actRetModel;
    }
}
